package com.itany.controller;

import com.itany.exception.ManagerException;
import com.itany.pojo.ManagerUser;
import com.itany.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * Author：侍家宇
 * Date：2019-09-18 上午9:51
 * Description：<描述>
 */
@Controller
@RequestMapping("/user")
public class ManagerUserController {
    @Autowired
    private ManagerService service;

    /**
     * 用户登录功能
     * @param
     */
    @RequestMapping("/login")
    public ModelAndView login(ManagerUser managerUser){
        ModelAndView mv = new ModelAndView();

        try {
            ManagerUser m = service.login(managerUser);
            mv.addObject("managerUser",m);
            mv.setViewName("index");
        } catch (ManagerException e) {
            mv.addObject("msg",e.getMessage());
            mv.setViewName("login");
        } catch (Exception e){
            e.printStackTrace();
            mv.setViewName("login");
            mv.addObject("msg","服务器异常");
        }
        return mv;
    }
}
